package com.tom.demo.controller.system;

import com.tom.demo.common.annotation.OperaLog;
import com.tom.demo.common.entity.SysPost;
import com.tom.demo.common.enumeration.OperaTypeEnum;
import com.tom.demo.common.response.Result;
import com.tom.demo.service.system.PostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = {"岗位管理"})
@RestController
@RequestMapping("/post")
public class PostController {
    @Resource
    private PostService postService;

    @PostMapping("/getPostPageList")
    @ApiOperation(value = "获取岗位列表信息")
    public Result getPostPageList(@RequestParam(value = "page",defaultValue = "1")Integer page,
                          @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                          @RequestBody SysPost sysPost){
        return postService.getPostPageList(page,pageSize,sysPost);
    }

    @PostMapping("/insertPost")
    @ApiOperation(value = "新增岗位")
    @OperaLog(operaModel = "岗位管理",operaType = OperaTypeEnum.ADD,operaDesc = "新增岗位")
    public Result insertPost(@RequestBody @Validated SysPost sysPost){
        return postService.insertPost(sysPost);
    }

    @PutMapping("/updatePost")
    @ApiOperation(value = "修改岗位")
    @OperaLog(operaModel = "岗位管理",operaType = OperaTypeEnum.UPDATE,operaDesc = "修改岗位")
    public Result updatePost(@RequestBody @Validated SysPost sysPost){
        return postService.updatePost(sysPost);
    }

    @DeleteMapping("/deleteByPostId/{postId}")
    @ApiOperation(value = "删除岗位")
    @OperaLog(operaModel = "岗位管理",operaType = OperaTypeEnum.DELETE,operaDesc = "删除岗位")
    public Result deleteByPostId(@PathVariable(value = "postId")String postId){
        return postService.deleteByPostId(postId);
    }
}
